package systems;

import java.util.ArrayList;

import general.Case;
import geometry.PointSI;
import graphique.C;

public class Arbre
{
	public Case case1;
	
	public int age;
	
	public Arbre(Case case1)
	{
		this.case1 = case1;
		
		age = (int) (Math.random() * C.nNivArbre * 8 );
		
		type = (int) (Math.random() * C.nDifArbre );
	}
	
	public ArrayList<Arbre> voisin = new ArrayList<Arbre>();

	public PointSI moy;

	public double	moyAlt;
	
	public double anglePhi;

	public double	angleTheta;

	public int	type;
	
	public int mode = 0;

	public int	inter = 0;

	public ArrayList<Double> disVoi = new ArrayList<Double>();
	
	public void decalage(double rX , double rY )
	{
		double altXm1 = case1.zone.p1.sx * rX + case1.zone.p2.sx * (1-rX);
		double altYm1 = case1.zone.p1.sy * rX + case1.zone.p2.sy * (1-rX);
		double altZm1 = case1.zone.p1.sz * rX + case1.zone.p2.sz * (1-rX);
		
		double altm1 = case1.zone.p1.alt * rX + case1.zone.p2.alt * (1-rX);
		
		double altXm2 = case1.zone.p4.sx * rX + case1.zone.p3.sx * (1-rX);
		double altYm2 = case1.zone.p4.sy * rX + case1.zone.p3.sy * (1-rX);
		double altZm2 = case1.zone.p4.sz * rX + case1.zone.p3.sz * (1-rX);
		
		double altm2 = case1.zone.p1.alt * rX + case1.zone.p2.alt * (1-rX);
		
		double altXm3 = altXm1 * rY + altXm2 * (1-rY);
		double altYm3 = altYm1 * rY + altYm2 * (1-rY);
		double altZm3 = altZm1 * rY + altZm2 * (1-rY);
		
		moyAlt = altm1 * rY + altm2 * (1-rY);
		
		moy = new PointSI(altXm3 , altYm3, altZm3);
		
		double rho = Math.sqrt( Math.pow(case1.zone.p1.sx, 2) + Math.pow(case1.zone.p1.sy, 2) + Math.pow(case1.zone.p1.sz, 2));
		double den = Math.sqrt( Math.pow(case1.zone.p1.sx, 2) + Math.pow(case1.zone.p1.sy, 2) );
		anglePhi = Math.acos( case1.zone.p1.sz/rho );
		
		//System.out.println("den : " + den + " x " + case1.zone.p1.sx + " r " + Math.acos( case1.zone.p1.sx / den ));
		if( case1.zone.p1.sy >= 0 )
			angleTheta = Math.acos( case1.zone.p1.sx / den );
		else
			angleTheta = 2 * Math.PI - Math.acos( case1.zone.p1.sx / den );
	}
}
